<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script type="text/javascript">
	/*
	触发历史管理：1.页面跳转	2.hash值改变	3.pushState
	*/

	window.onload = function (){
		var oBtn = document.getElementById('btn1');
		var oDiv = document.getElementById('div1');
		var json = {};

		oBtn.onclick = function (){
			var num = Math.random();		//num作为不带“#”号的、剩下的hash值
			var arr = randomNum(35,7);

			json[num] = arr;				//形如json={num:[***]}
			oDiv.innerHTML = arr;
			window.location.hash = num;
		};

		window.onhashchange = function (){
			oDiv.innerHTML = json[window.location.hash.substring(1)];		//截取了不带“#”号的、剩下的hash值，也就是num
		}

		function randomNum(iAll, iNow){
			var arr = [];
			var newArr = [];

			for (var i = 1; i <= iAll; i++) {
				arr.push(i);
			};
			
			for (var i = 0; i < iNow; i++) {
				var del = Math.floor( Math.random()*arr.length );		//这样取得35的概率会不会很低
				newArr.push( arr.splice(del, 1) );						//将删除的值返回到newArr里
			};
			return newArr;
		}
	}
	</script>
</head>
<body>
	<input type="button" value="随即选择" id="btn1" />
	<div id="div1"></div>
</body>
</html>